package com.project.controller;

import com.project.entity.Discuss;
import com.project.entity.KnowLedge;
import com.project.entity.Question;
import com.project.entity.Result;
import com.project.service.DiscussService;
import com.project.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @GetMapping("findPage/{pageIndex}/{pageItemCount}")
    public Result findAll(@PathVariable int pageIndex,@PathVariable int pageItemCount){
        Result result = new Result();
        try {
            List<Question> questionList = questionService.findPage(pageIndex, pageItemCount);
            result.success("成功");
            result.putData("questionList",questionList);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping("addQuestion")
    public Result addQuestion( Question question){
        Result result = new Result();
        try {
//            System.out.println(question);
            questionService.addQuestion(question);
            result.success("成功");
        }catch (Exception e) {
            result.error(e.getMessage());
        }
        return result;
    }
}
